#!/usr/bin/python3

import pymysql
import time
import os

# 打开数据库连接
db = pymysql.connect(host="123.206.49.104", user="public",
                     passwd="koo@20161109", db="koo", charset="utf8", port=3306)

# 使用cursor()方法获取操作游标
cursor = db.cursor()

# SQL 查询语句
sql = ("SELECT * FROM t_roomplaybackrecordinfo WHERE status != '%d'" %
       (3))
try:
    # 执行SQL语句
    num = cursor.execute(sql)
    # 获取所有记录列表
    results = cursor.fetchall()
    #print (results)
    for index in range(num):
        item = results[index]
        localt = time.localtime(item[5])
        stime = time.strftime("%Y-%m-%d %H:%M:%S", localt)
        print("%d roomid:%d, status:%d, title:%s, rebegintime:%s, url:%s" %
              (index, item[0], item[1], item[2], stime, item[9]))
except:
    print("Error: unable to fetch data")

# 关闭数据库连接
db.close()
os.system('pause')
